package handler

import (
	"github.com/gin-gonic/gin"
	request2 "zg3yk/api/request"
	"zg3yk/interface/dao"
	"zg3yk/interface/models"
	"zg3yk/pkg"
)

func Login(context *gin.Context) {

	var req request2.LoginReq

	err := context.ShouldBind(&req)
	if err != nil {
		context.JSON(500, gin.H{
			"code": 500,
			"msg":  "登录失败",
			"data": nil,
		})
		return
	}

	var user models.Users

	dao.Find(req.Id, &user)
	token, err := pkg.NewJWT("lx").CreateToken(pkg.CustomClaims{
		ID: req.Id,
	})
	if err != nil {
		return
	}

	context.JSON(200, gin.H{
		"code": 200,
		"msg":  "登录成功",
		"data": token,
	})

}
